package com.tjsinfo.tjsoa.mail.action;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.mail.bo.ITjsEmailFolderBo;
import com.tjsinfo.tjsoa.mail.bo.ITjsFoldMailBo;
import com.tjsinfo.tjsoa.mail.vo.TjsFoldMail;

/**
 * 删除文件夹
 * @author wangxiaowei
 *
 */
public class DeleteEmailFloderAction extends Action{
	private ITjsFoldMailBo tjsFoldMailBo;
	private ITjsEmailFolderBo tjsEmailFolderBo;
	public ITjsEmailFolderBo getTjsEmailFolderBo() {
		return tjsEmailFolderBo;
	}

	public void setTjsEmailFolderBo(ITjsEmailFolderBo tjsEmailFolderBo) {
		this.tjsEmailFolderBo = tjsEmailFolderBo;
	}

	public ITjsFoldMailBo getTjsFoldMailBo() {
		return tjsFoldMailBo;
	}

	public void setTjsFoldMailBo(ITjsFoldMailBo tjsFoldMailBo) {
		this.tjsFoldMailBo = tjsFoldMailBo;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		String id = null;
		if(request.getParameter("flodid") != null && !"".equals(request.getParameter("flodid")))
		{
			 id = request.getParameter("flodid");
		}
		else
		{
			id = request.getParameter("foldid");
		}
		List list =	tjsFoldMailBo.selectTjsFoldMailByFoldId(id);//文件夹邮件列表
		String[]array =new  String[list.size()];
		int i = 0;
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			TjsFoldMail tjsFoldMail = (TjsFoldMail) iterator.next();
			array[i] = String.valueOf(tjsFoldMail.getTjsmailId());
			i++;
		}
		tjsFoldMailBo.deleteTjsEmailFoldList(array, SessionUser.getUser(request).getUsername());
		tjsEmailFolderBo.deleteTjsEmailFold(id);
		request.setAttribute("linkurl", "tjsinfo/tjsoa/mail/emailReceivedList.do");
		request.setAttribute("message", "email.message.deleteemail");
		return mapping.findForward("success");
		
		
	}
	
}
